package panda.index.bplustree;

import panda.record.TableToken;
import panda.buffer.*;
import panda.file.*;
import panda.query.*;
import static panda.file.Page.INT_SIZE;
import static panda.file.Page.BLOCK_SIZE;
import static java.sql.Types.*;

public class FileHeader implements PageFormatter {
	private TableToken tblToken;
	private int flag;
	
	FileHeader(TableToken tt, int f) {
		tblToken = tt;
		flag = f;
	}
	
	public TableToken getTableToken() {
		return tblToken;
	}
	
	public int getFlag() {
		return flag;
	}
	
	public void format(Page page) {
		page.putInt(0, flag);
		page.putInt(INT_SIZE, 0);
		
		int record = tblToken.getTupleLength();
		int i = 0;
		
		for (i = 2 * INT_SIZE; i + record <= BLOCK_SIZE; i+= record) {
			makeDefaultRecord(page, i);
		}
	}
	
	//TODO
	private void makeDefaultRecord(Page page, int pos) {
		for (String attr : tblToken.getSchema().getAllAttributeNames()) {
			int offset = tblToken.offsetOf(attr);
			
			if (tblToken.getSchema().getType(attr) == INTEGER) {
				page.putInt(offset + pos, 0);
			}
		}
	}
}